import Vue from "vue";
import VueRouter from "vue-router";

//解决连续点击同个路由出bug
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect : '/home'
  },
  {
    path: "/reg",
    name: "reg",
    component: () => import('../views/Reg'),
    meta : {
      title : '注册页',
      nocheck : true //不用路由守卫：谁都能看
    }
  },
  {
    path: "/login",
    name: "login",
    component: () => import('../views/Login'),
    meta : {
      title : '登录页',
      nocheck : true//不用路由守卫：谁都能看
    }
  },
  {
    path: "/home",
    name: "home",
    component: () => import('../views/Layout'),
    meta : {
      title : '主页面'
    },
    redirect : '/home/users',
    children:[
      {
        path : 'users',
        component: () => import('../views/Users'),
        name: "users",
        meta : {
          title : '用户管理'
        },
        //路由表的路由守卫
        // beforeEnter(to,from,next) {
        // }
      },{
        path : 'orders',
        component: () => import('../views/Orders'),
        name: "orders",
        meta : {
          title : '订单管理'
        }
      },{
        path : 'goods',
        component: () => import('../views/Goods'),
        name: "goods",
        meta : {
          title : '商品管理'
        }
      },{
        path : 'comments',
        component: () => import('../views/Comments'),
        name: "comments",
        meta : {
          title : '评论管理'
        }
      }
    ]
  },
];




const router = new VueRouter({
  routes
});

//全局路由钩子
// router.beforeEach(function (to, from, next) {
//   console.log(to,'to');
//   console.log(from,'from');
//   window.console.log("进入全局 beforeEach钩子了");
//   next();
// })

export default router;
